import * as echarts from '../../ec-canvas/echarts';
Component({
    properties: {
        xData: Array,
        yData: Array
    },

    data: {
        ec: {
            lazyLoad: true
        },
        xdata: [],
        ydata: []
    },

    lifetimes: {
        attached() {
            // 初始化图表
            this.getTrend();
        }
    },

    methods: {
        getTrend() {
            const ecComponent = this.selectComponent('#mychart-dom-bar');
            if (!ecComponent) return;

            ecComponent.init((canvas, width, height, dpr) => {
                const chart = echarts.init(canvas, null, { width, height, devicePixelRatio: dpr });

                const option = {
                    xAxis: { type: 'category', data: this.properties.xData },
                    yAxis: { type: 'value' },
                    series: [{ data: this.properties.yData, type: 'bar' }]
                };

                chart.setOption(option);
                return chart;
            });
        }
    },

    observers: {
        xData(newVal) { this.getTrend(); },
        yData(newVal) { this.getTrend(); }
    }
});

